# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

def expect_network_get_soa(serial, id, extra = {})
  body = load_network_result("soa#{id}-#{serial}.yaml").to_json
  request = double('request')
  allow(request).to receive(:send).and_return(http_success(body))
  extra = extra.merge(name: '.', type: :SOA)
  expect(Google::<%= product_ns -%>::Network::Get).to receive(:new)
    .with(self_link(uri_data(id).merge(extra)),
          instance_of(Google::FakeAuthorization))
    .and_return(request)
end

def expect_network_create_change(change_id, id, done, expected_body,
                                 extra = {})
  body = {
    kind: 'dns#change',
    id: change_id,
    status: done ? 'done' : 'pending'
  }.to_json

  request = double('request')
  allow(request).to receive(:send).and_return(http_success(body))

  expect(Google::<%= product_ns -%>::Network::Post).to receive(:new)
    .with(collection(uri_data(id).merge(extra)),
          instance_of(Google::FakeAuthorization),
          'application/json', expected_body.to_json)
    .and_return(request)
end
